/*
This file replicates the empirical tables and figures in:
When TED Talks, Does Anyone Listen? A New Dataset on Political Leadership
Review of International Organizations, TBD

(Last updated 02 March 2022)

Authors: Thomas E. Flores, Gabriella Lloyd, Irfan Nooruddin

This replication do-file references five data-files:

1) FLN TED Leader Level Dataset.dta

2) FLN TED Country-Year Dataset.dta

3) FLN TED Empirical Analysis.dta

4) idfile.dta 

5) coord_mercator_world.dta

To create the maps in Figure 6, ID (#4 above) and Coord (#5 above) files for SPMAP are 
also required.  The files used by the authors are provided here, but the originals 
can be obtained at this link: https://www.stathelp.se/en/spmap_world_en.html

*/

cd // Change working directory to wherever all the data-files (5 in total) are saved
set more off 

********************************************************************************
* Figure 1. Family Social Class and Highest Degree Attained by Heads of Government, 1945-2015 
* Note: This figure was created in Word. This code will replicate the values used in this figure.

use "FLN TED Leader Level Dataset.dta"
tab fln_highestdegree
tab fln_familyclass

********************************************************************************
* Figure 2. Where Leaders Receive Their Higher Educations, 1945-2015 
* Note: This figure was created in Word. This code will replicate the values used in this figure.

use "FLN TED Leader Level Dataset.dta"

* American, British, or French University - Prestigious University
qui tab fln_leader if (fln_uni_us == 1 | fln_uni_ukf == 1) & ( fln_prest_us == 1 | fln_prest_europe == 1)
di r(r)
*186

* American, British, or French University -	Top-50 (Not Prestigious)
qui tab fln_leader if (fln_uni_us == 1 | fln_uni_ukf == 1) & ( fln_prest_us == 0 & fln_prest_europe == 0) & fln_top50 == 1
di r(r)
* 32

*American, British, or French University - Other University
qui tab fln_leader if (fln_uni_us == 1 | fln_uni_ukf == 1) & ( fln_prest_us == 0 & fln_prest_europe == 0) & fln_top50 == 0 & fln_highestdegree != "military"
di r(r)
* 195

*American, British, or French University - Military degree
qui tab fln_leader if (fln_uni_us == 1 | fln_uni_ukf == 1) & ( fln_prest_us == 0 & fln_prest_europe == 0) & fln_top50 == 0 & fln_highestdegree == "military"
di r(r)
* 41


*University Outside of US, UK, FR - Top-50 University
qui tab fln_leader if (fln_uni_us == 0 & fln_uni_ukf == 0) & fln_top50 == 1 
di r(r)
* 18

*University Outside of US, UK, FR - Military degree
qui tab fln_leader if (fln_uni_us == 0 & fln_uni_ukf == 0) &  fln_highestdegree == "military"
di r(r)
* 114

* University Outside of US, UK, FR - Other University
qui tab fln_leader if (fln_uni_us == 0 & fln_uni_ukf == 0) & fln_top50 == 0 & (fln_highestdegree == "undergraduate" | fln_highestdegree == "graduate")
di r(r)
* 653

* No University Degree - No military degree 
qui tab fln_leader if (fln_uni_us == 0 & fln_uni_ukf == 0) & fln_top50 == 0 & (fln_highestdegree != "undergraduate" & fln_highestdegree != "graduate" & fln_highestdegree != "military" & fln_highestdegree != ".")
di r(r)
* 170

* No University Degree - Military degree
qui tab fln_leader if (fln_uni_us == 0 & fln_uni_ukf == 0) & fln_top50 == 0 & (fln_highestdegree == "military" )
di r(r)
* 114

********************************************************************************
* Figure 3. Temporal Trends in Western University Attendance by Heads of Government, 1945-2015 
use "FLN TED Country-Year Dataset.dta", clear

set scheme economist

gen yearchart=.
local n=1                                         
	qui sum year                                
	forvalues i=`r(min)'(1)`r(max)' {           
		replace yearchart=`i' if _n==`n'
		local n=`n'+1                            
		}


gen abroad=.
gen prestUS=.
gen prestEU=.
gen USuni=.
gen EUuni=.
gen top50=.

levelsof yearchart, local(y)
foreach j of local y {

	qui sum fln_abroad if year==`j', d
	replace abroad =r(mean) if yearchart==`j'  
	
	qui sum fln_prest_us if year==`j' , d
	replace prestUS =r(mean) if yearchart==`j'  	    

	qui sum fln_prest_europe if year==`j'  , d        
	replace prestEU =r(mean) if yearchart==`j'    
	
	qui sum fln_uni_us if year==`j'  , d       
	replace USuni =r(mean) if yearchart==`j'    
	
	qui sum fln_uni_ukf if year==`j'  , d        
	replace EUuni =r(mean) if yearchart==`j'  
	
	qui sum fln_top50 if year==`j', d       
	replace top50 =r(mean) if yearchart==`j'    
}

replace abroad = abroad*100
replace prestUS = prestUS* 100
replace prestEU = prestEU * 100
replace USuni = USuni * 100
replace  EUuni = EUuni * 100
replace top50 = top50 * 100

line  prestUS prestEU USuni EUuni yearchart

********************************************************************************
* Figure 4. Temporal Trends in Highest Degree Received by Heads of Government, 1945-2015 
use "FLN TED Country-Year Dataset.dta", clear

set scheme economist

gen yearchart=.
local n=1                                         
	qui sum year                                
	forvalues i=`r(min)'(1)`r(max)' {           
		replace yearchart=`i' if _n==`n'
		local n=`n'+1                            
		}
		
gen graduate=.
gen undergraduate=.
gen military=.
gen secondary=.
gen primary=.

gen graduatedum =.
replace graduatedum = 1 if fln_highestdegree == "graduate"
replace graduatedum = 0 if fln_highestdegree != "graduate" & fln_highestdegree != "."

gen undergraduatedum =.
replace undergraduatedum = 1 if fln_highestdegree == "undergraduate"
replace undergraduatedum = 0 if fln_highestdegree != "undergraduate" & fln_highestdegree != "."

gen militarydum =.
replace militarydum = 1 if fln_highestdegree == "military"
replace militarydum = 0 if fln_highestdegree != "military" & fln_highestdegree != "."

gen secondarylessdum =.
replace secondarylessdum = 1 if fln_highestdegree == "secondary" | fln_highestdegree == "primary" | fln_highestdegree == "none" 
replace secondarylessdum = 0 if secondarylessdum != 1 & fln_highestdegree != "."


levelsof yearchart, local(y)
foreach j of local y {

	qui sum graduatedum if year==`j', d
	replace graduate =r(mean) if yearchart==`j'  
	
	qui sum undergraduatedum if year==`j' , d
	replace undergraduate =r(mean) if yearchart==`j'  	    

	qui sum militarydum if year==`j'  , d        
	replace military =r(mean) if yearchart==`j'    
	
	qui sum secondarylessdum if year==`j'  , d       
	replace secondary =r(mean) if yearchart==`j'    
	
	}

replace graduate = graduate*100
replace undergraduate = undergraduate* 100
replace military = military * 100
replace secondary = secondary * 100

line graduate undergraduate military secondary yearchart

********************************************************************************
* Figure 5. Temporal Trends in Technocratic Employment Credentials, 1945-2015
 
use "FLN TED Country-Year Dataset.dta", clear

set scheme economist

gen yearchart=.
local n=1                                         
	qui sum year                                
	forvalues i=`r(min)'(1)`r(max)' {           
		replace yearchart=`i' if _n==`n'
		local n=`n'+1                            
		}
		
gen anyemp=.
gen business=.
gen econjob=.
gen field=.
gen ifi=.

gen techemployment  = 1 if fln_imf == 1 | fln_worldbank == 1 | fln_un == 1 | fln_wto == 1 | fln_moneycenterbank == 1 | fln_regionalbank == 1 | fln_field == 1 | fln_econjob == 1 | fln_businessman ==1
replace techemployment= 0 if fln_imf == 0 & fln_worldbank == 0 & fln_un == 0 & fln_wto == 0 & fln_moneycenterbank == 0 &fln_regionalbank == 0 & fln_field == 0 & fln_econjob == 0 & fln_businessman == 0

gen ifidum = 1 if fln_imf == 1 | fln_worldbank == 1 | fln_un == 1 | fln_wto == 1 | fln_moneycenterbank == 1 | fln_regionalbank == 1
replace ifidum= 0 if fln_imf == 0 & fln_worldbank == 0 & fln_un == 0 & fln_wto == 0 & fln_moneycenterbank == 0 &fln_regionalbank == 0

levelsof yearchart, local(y)
foreach j of local y {

	qui sum techemployment if year==`j', d
	replace anyemp =r(mean) if yearchart==`j'  
	
	qui sum ifidum if year==`j' , d
	replace ifi =r(mean) if yearchart==`j'  	    

	qui sum fln_field if year==`j'  , d        
	replace field =r(mean) if yearchart==`j'    
	
	qui sum fln_businessman if year==`j'  , d       
	replace business =r(mean) if yearchart==`j'    
	
	qui sum fln_econjob if year==`j'  , d       
	replace econjob =r(mean) if yearchart==`j'    

	}

replace anyemp = anyemp*100
replace ifi = ifi* 100
replace field = field * 100
replace business = business * 100
replace econjob = econjob * 100

line anyemp  ifi field business econjob yearchart

********************************************************************************
* Figure 6. Spatial Trends in Leaders’ Education and Employment Credentials, 1945-2015 

* Education in Prestigious or Top-50 Universities, 1945-2015
use "FLN TED Leader Level Dataset.dta", clear


gen elite_education  = 1 if fln_prest_europe == 1 | fln_prest_us == 1 | fln_top50 == 1 
replace elite_education  = 0 if  fln_highestdegree != "." & fln_prest_europe == 0 & fln_prest_us == 0 & fln_top50 == 0 

collapse (mean)  elite_education  , by(cowcode)
replace elite_education = elite_education * 100


rename cowcode COWcode

merge 1:m COWcode using "idfile.dta"


spmap elite_education using "coord_mercator_world.dta", id(na_id_world) fcolor(PuBuGn) osize(vvthin vvthin vvthin vvthin) ndsize(vvthin) title("Education in Prestigious or Top-50 Universities, 1945-2015") clmethod(custom) clbreaks(0 25  50  75 100)


* Tehnocratic Employment Experience, 1945-2015
use "FLN TED Leader Level Dataset.dta", clear

gen techemployment  = 1 if fln_imf == 1 | fln_worldbank == 1 | fln_un == 1 | fln_wto == 1 | fln_moneycenterbank == 1 | fln_regionalbank == 1 |  fln_econjob == 1 | fln_businessman ==1
replace techemployment= 0 if fln_imf == 0 & fln_worldbank == 0 & fln_un == 0 & fln_wto == 0 & fln_moneycenterbank == 0 &fln_regionalbank == 0 & fln_econjob == 0 & fln_businessman == 0


collapse (mean)  techemployment  , by(cowcode)
replace techemployment = techemployment * 100

rename cowcode COWcode

merge 1:m COWcode using "idfile.dta"


spmap techemployment using "coord_mercator_world.dta", id(na_id_world) fcolor(PuBuGn) osize(vvthin vvthin vvthin vvthin) ndsize(vvthin) title("Technocratic Employment Experience, 1945-2015") clmethod(custom) clbreaks(0 25  50  75 100)

* Graduate Degrees or Technocratic Fields of Study, 1945-2015

use "FLN TED Leader Level Dataset.dta", clear

gen grad_or_field  = 1 if fln_highestdegree == "graduate" | fln_field == 1
replace grad_or_field= 0 if fln_highestdegree != "graduate" & fln_highestdegree != "." & fln_field == 0


collapse (mean)  grad_or_field  , by(cowcode)
replace grad_or_field = grad_or_field * 100

rename cowcode COWcode

merge 1:m COWcode using "idfile.dta"


spmap grad_or_field using "coord_mercator_world.dta", id(na_id_world) fcolor(PuBuGn) osize(vvthin vvthin vvthin vvthin) ndsize(vvthin) title("Graduate Degrees or Technocratic Fields of Study, 1945-2015") clmethod(custom) clbreaks(0 25  50  75 100)

********************************************************************************
* Figure 7.  Education and Employment Experiences of Leaders in Countries with Different Democratic and Development Status, 1945-2015 
use "FLN TED Empirical Analysis.dta", clear

gen democracy_development = .
* 1 = Developing democracies
replace democracy_development = 1 if democracy == 1 & developing == 1
* 2 = Wealthy democracies
replace democracy_development = 2 if democracy == 1 & developing == 0
* 3 = Developing non-democracies
replace democracy_development = 3 if democracy == 0 & developing == 1
* 4 = Wealthy non-democracies
replace democracy_development = 4 if democracy == 0 & developing == 0

cap drop elite_education
gen elite_education  = 1 if fln_prest_europe == 1 | fln_prest_us == 1 | fln_top50 == 1 
replace elite_education  = 0 if  fln_highestdegree != "." & fln_prest_europe == 0 & fln_prest_us == 0 & fln_top50 == 0 
replace elite_education = elite_education *100

gen military = 1 if  fln_highestdegree == "military"
replace military = 0 if fln_highestdegree != "military" & fln_highestdegree != "."
replace military = military * 100

gen techexperience  = 1 if fln_imf == 1 | fln_worldbank == 1 | fln_un == 1 | fln_wto == 1 | fln_moneycenterbank == 1 | fln_regionalbank == 1 |  fln_econjob == 1 | fln_businessman ==1
replace techexperience= 0 if fln_imf == 0 & fln_worldbank == 0 & fln_un == 0 & fln_wto == 0 & fln_moneycenterbank == 0 &fln_regionalbank == 0 & fln_econjob == 0 & fln_businessman == 0
replace techexperience = techexperience *100

gen grad_or_field  = 1 if fln_highestdegree == "graduate" | fln_field == 1
replace grad_or_field= 0 if fln_highestdegree != "graduate" & fln_highestdegree != "." & fln_field == 0
replace grad_or_field = grad_or_field *100

ssc install cibar, replace
cibar elite_education, over(democracy_development) 
cibar techexperience, over(democracy_development) 
cibar grad_or_field, over(democracy_development) 
cibar military, over(democracy_development) 


********************************************************************************
* Figure 8. Proportion of Leaders from Poor, Middle Class, and Wealthy Families with the Prestigious Education and Technocratic Employment Credentials in TED, 1945-2015 

use "FLN TED Leader Level Dataset.dta", clear

gen elite_education  = 1 if fln_prest_europe == 1 | fln_prest_us == 1 | fln_top50 == 1 
replace elite_education  = 0 if  fln_highestdegree != "." & fln_prest_europe == 0 & fln_prest_us == 0 & fln_top50 == 0 
replace elite_education = elite_education *100

gen military = 1 if  fln_highestdegree == "military"
replace military = 0 if fln_highestdegree != "military" & fln_highestdegree != "."
replace military = military * 100

gen techexperience  = 1 if fln_imf == 1 | fln_worldbank == 1 | fln_un == 1 | fln_wto == 1 | fln_moneycenterbank == 1 | fln_regionalbank == 1 |  fln_econjob == 1 | fln_businessman ==1
replace techexperience= 0 if fln_imf == 0 & fln_worldbank == 0 & fln_un == 0 & fln_wto == 0 & fln_moneycenterbank == 0 &fln_regionalbank == 0 & fln_econjob == 0 & fln_businessman == 0
replace techexperience = techexperience *100

gen grad_or_field  = 1 if fln_highestdegree == "graduate" | fln_field == 1
replace grad_or_field= 0 if fln_highestdegree != "graduate" & fln_highestdegree != "." & fln_field == 0
replace grad_or_field = grad_or_field *100

* 1 = poor
gen fln_familyclass_num =  1 if fln_familyclass == "poor"
* 2 = middle class
replace fln_familyclass_num =  2 if fln_familyclass == "middle"
* 3 = rich 
replace fln_familyclass_num =  3 if fln_familyclass == "rich"

cibar elite_education, over(fln_familyclass_num) 
cibar military, over(fln_familyclass_num) 
cibar techexperience, over(fln_familyclass_num) 
cibar grad_or_field, over(fln_familyclass_num) 

********************************************************************************
* Figure 9. Proportion of Leaders from Right-of-Center and Left-of-Center Parties with the Education and Employment Credentials in TED, 1945-2015 

use "FLN TED Empirical Analysis.dta", clear

collapse (max) dpi_erlc cowcode fln_top50     fln_field  fln_uni_us fln_prest_us fln_uni_ukf fln_prest_europe fln_moneycenterbank fln_imf fln_worldbank fln_un fln_wto fln_regionalbank fln_businessman fln_econjob fln_us_weurope  (first) fln_highestdegree, by(fln_leader)


gen elite_education  = 1 if fln_prest_europe == 1 | fln_prest_us == 1 | fln_top50 == 1 
replace elite_education  = 0 if  fln_highestdegree != "." & fln_prest_europe == 0 & fln_prest_us == 0 & fln_top50 == 0 
replace elite_education = elite_education *100

gen techexperience  = 1 if fln_imf == 1 | fln_worldbank == 1 | fln_un == 1 | fln_wto == 1 | fln_moneycenterbank == 1 | fln_regionalbank == 1 |  fln_econjob == 1 | fln_businessman ==1
replace techexperience= 0 if fln_imf == 0 & fln_worldbank == 0 & fln_un == 0 & fln_wto == 0 & fln_moneycenterbank == 0 &fln_regionalbank == 0 & fln_econjob == 0 & fln_businessman == 0
replace techexperience = techexperience *100

gen grad_or_field  = 1 if fln_highestdegree == "graduate" | fln_field == 1
replace grad_or_field= 0 if fln_highestdegree != "graduate" & fln_highestdegree != "." & fln_field == 0
replace grad_or_field = grad_or_field *100

cibar elite_education if dpi_erlc != 2, over(dpi_erlc) 
cibar techexperience  if dpi_erlc != 2, over(dpi_erlc) 
cibar grad_or_field  if dpi_erlc != 2, over(dpi_erlc) 

* Legend for dpi_erlc
* right-of-center = 1
* center = 2
* left-of-center = 3

********************************************************************************
* Figure 10. How the Countries Rated by Moody’s Have Changed Over Time 

use  "FLN TED Empirical Analysis.dta", clear

keep if moody_rated_fc == 1

collapse (p50) vdem_corrp50=vdem_corr vdem_libdemp50=vdem_libdem v2clrspctp50=v2clrspct (p25) vdem_corrp25=vdem_corr vdem_libdemp25=vdem_libdem v2clrspctp25=v2clrspct (p75) vdem_corrp75=vdem_corr vdem_libdemp75=vdem_libdem v2clrspctp75=v2clrspct, by(year) 

sort year
graph twoway line vdem_libdemp50 vdem_libdemp25 vdem_libdemp75 year, name(g1, replace)
graph twoway line vdem_corrp50 vdem_corrp25 vdem_corrp75 year, name(g2, replace)
graph twoway line v2clrspctp50 v2clrspctp25 v2clrspctp75 year, name(g3, replace)

*help grc1leg // In case you need to install 'grc1leg'
grc1leg g1 g2 g3
********************************************************************************
* Figure 11. Comparing Moody’s, S&P’s, and Fitch ratings assigned to countries with and without leaders possessing elite educations 

use "FLN TED Empirical Analysis.dta", clear

cibar moody_rating_fc, over(elite_education)
cibar sp_rating_fc, over(elite_education)
cibar fitch_rating_fc, over(elite_education)

********************************************************************************
* Table 3. The effect of leaders’ educational credentials on sovereign debt ratings, 1958-2015 

use "FLN TED Empirical Analysis.dta", clear

* Model 1
xtreg moody_rating_fc elite_education  newtech l1.combined_default  l1.gdppdc_log l1.GDPpcgrowth l1.currentacct_gdp l1.reserves_gdp l1.resources_me l1.trade_gdp l1.inflation l1.democracy l1.h_polcon5 l1.h_j l1.vdem_corr l1.civilconflict   year if year<=2015 & developing == 1, fe cluster(cowcode)
sum year if e(sample)


* Model 2
xtreg sp_rating_fc elite_education  newtech l1.combined_default  l1.gdppdc_log l1.GDPpcgrowth l1.currentacct_gdp l1.reserves_gdp l1.resources_me l1.trade_gdp l1.inflation l1.democracy l1.h_polcon5 l1.h_j l1.vdem_corr l1.civilconflict   year if year<=2015 & developing == 1, fe cluster(cowcode)
sum year if e(sample)

* Model 3
xtreg fitch_rating_fc elite_education  newtech l1.combined_default  l1.gdppdc_log l1.GDPpcgrowth l1.currentacct_gdp l1.reserves_gdp l1.resources_me l1.trade_gdp l1.inflation l1.democracy l1.h_polcon5 l1.h_j l1.vdem_corr l1.civilconflict   year if year<=2015 & developing == 1, fe cluster(cowcode)
sum year if e(sample)

********************************************************************************
* Table 4. Downgrades are rare during educational elites’ first year in office 

use "FLN TED Empirical Analysis.dta", clear

drop fln_entry_year
egen fln_entry_year = min(year), by(fln_leader cowcode)

gen fln_firstyear=.
replace fln_firstyear=0 if year~=fln_entry_year
replace fln_firstyear=1 if year==fln_entry_year
replace fln_firstyear=. if fln_entry_year==. 

* Calculate numbers
* Moody's
tab elite_education moody_change_fc if year<=2015 & developing == 1 & fln_firstyear == 1,  row taub
* S&P's
tab elite_education sp_change_fc if year<=2015 & developing == 1 & fln_firstyear == 1,  row taub
* Fitch's 
tab elite_education fitch_change_fc if year<=2015 & developing == 1 & fln_firstyear == 1,  row taub

* T-tests
* Moody's
gen moody_downgrade = 1 if moody_change_fc == -1
replace moody_downgrade = 0 if moody_change_fc == 0 | moody_change_fc == 1
ttest moody_downgrade if year<=2015 & developing == 1 & fln_firstyear == 1, by(elite_education) 

gen moody_nochange = 1 if moody_change_fc == 0
replace moody_nochange = 0 if moody_change_fc == -1 | moody_change_fc == 1
ttest moody_nochange if year<=2015 & developing == 1 & fln_firstyear == 1, by(elite_education) 

gen moody_upgrade = 1 if moody_change_fc == 1
replace moody_upgrade = 0 if moody_change_fc == -1 | moody_change_fc == 0
ttest moody_upgrade if year<=2015 & developing == 1 & fln_firstyear == 1, by(elite_education) 

*S&P's
gen sp_downgrade = 1 if sp_change_fc == -1
replace sp_downgrade = 0 if sp_change_fc == 0 | sp_change_fc == 1
ttest sp_downgrade if year<=2015 & developing == 1 & fln_firstyear == 1, by(elite_education) 

gen sp_nochange = 1 if sp_change_fc == 0
replace sp_nochange = 0 if sp_change_fc == -1 | sp_change_fc == 1
ttest sp_nochange if year<=2015 & developing == 1 & fln_firstyear == 1, by(elite_education) 

gen sp_upgrade = 1 if sp_change_fc == 1
replace sp_upgrade = 0 if sp_change_fc == -1 | sp_change_fc == 0
ttest sp_upgrade if year<=2015 & developing == 1 & fln_firstyear == 1, by(elite_education) 

*Fitch
gen fitch_downgrade = 1 if fitch_change_fc == -1
replace fitch_downgrade = 0 if fitch_change_fc == 0 | fitch_change_fc == 1
ttest fitch_downgrade if year<=2015 & developing == 1 & fln_firstyear == 1, by(elite_education) 

gen fitch_nochange = 1 if fitch_change_fc == 0
replace fitch_nochange = 0 if fitch_change_fc == -1 | fitch_change_fc == 1
ttest fitch_nochange if year<=2015 & developing == 1 & fln_firstyear == 1, by(elite_education) 

gen fitch_upgrade = 1 if fitch_change_fc == 1
replace fitch_upgrade = 0 if fitch_change_fc == -1 | fitch_change_fc == 0
ttest fitch_upgrade if year<=2015 & developing == 1 & fln_firstyear == 1, by(elite_education) 

********************************************************************************
********************************************************************************
* Appendix

use "FLN TED Empirical Analysis.dta", clear

********************************************************************************
* TABLE A1. The effect of leaders’ educational credentials (with transformed DV) 
xtreg moody_rating_fc_t elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5 l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation year if year<=2015 & developing == 1, fe cluster(cowcode)

xtreg sp_rating_fc_t elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5 l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation year if year<=2015 & developing == 1, fe cluster(cowcode)

********************************************************************************
* TABLE A2. Effects of educational elites, political ideology, and family class on Moody’s ratings (estimated using transformed DVs) 
* Controlling for ideology
xtreg moody_rating_fc_t elite_education  newtech ib2.dpi_erlc  l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5 l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation year if year<=2015 & developing == 1, fe cluster(cowcode)

* Controlling for family class
gen fln_familyclass_n = 1 if fln_familyclass == "poor"
replace fln_familyclass_n = 2 if fln_familyclass == "middle"
replace fln_familyclass_n = 3 if fln_familyclass == "rich"

xtreg moody_rating_fc_t elite_education  newtech ib2.fln_familyclass_n  l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5 l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation year if year<=2015 & developing == 1, fe cluster(cowcode)

* Controlling for ideology and class
xtreg moody_rating_fc_t elite_education ib2.fln_familyclass_n ib2.dpi_erlc newtech   l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5 l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation year if year<=2015 & developing == 1, fe cluster(cowcode)

********************************************************************************
* TABLE A3. Estimating the effects of educational elites using Heckman selection models and the KOF Index of Social Globalization as an instrument   

* Moody's
	* Original DV
xi: heckman moody_rating_fc elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5 l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation year if year<=2015 & developing == 1, select (moody_rated_fc= elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5  newtech l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation ld.dr_sg year ) cluster(cowcode)
	* Transformed DV
xi: heckman moody_rating_fc_t elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5 l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation year if year<=2015 & developing == 1, select (moody_rated_fc= elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5  newtech l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation ld.dr_sg year ) cluster(cowcode)

* S&P's
	* Original DV
xi: heckman sp_rating_fc elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5 l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation year if year<=2015 & developing == 1, select (sp_rated_fc= elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5  newtech l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation ld.dr_sg year ) cluster(cowcode)
	* Transformed DV
xi: heckman sp_rating_fc_t elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5 l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation year if year<=2015 & developing == 1, select (sp_rated_fc= elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5  newtech l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation ld.dr_sg year ) cluster(cowcode)

* Fitch
	* Original DV
xi: heckman fitch_rating_fc elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5 l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation year if year<=2015 & developing == 1, select (fitch_rated_fc= elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5  newtech l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation ld.dr_sg year ) cluster(cowcode)
	* Transformed DV
xi: heckman fitch_rating_fc_t elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5 l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation year if year<=2015 & developing == 1, select (fitch_rated_fc= elite_education   newtech l1.civilconflict l1.vdem_corr l1.h_j l1.h_polcon5  newtech l1.currentacct_gdp l1.resources_me l1.democracy l1.combined_default l1.gdppdc_log l1.GDPpcgrowth l1.trade_gdp l1.reserves_gdp l1.inflation ld.dr_sg year ) cluster(cowcode)

********************************************************************************
* TABLE A4. Correlation coefficients  

qui xtreg moody_rating_fc elite_education  newtech l1.combined_default  l1.gdppdc_log l1.GDPpcgrowth l1.currentacct_gdp l1.reserves_gdp l1.resources_me l1.trade_gdp l1.inflation l1.democracy l1.h_polcon5 l1.h_j l1.vdem_corr l1.civilconflict   year if year<=2015 & developing == 1, fe cluster(cowcode)

qui corr elite_education  newtech l1.combined_default  l1.gdppdc_log l1.GDPpcgrowth l1.currentacct_gdp l1.reserves_gdp l1.resources_me l1.trade_gdp l1.inflation l1.democracy l1.h_polcon5 l1.h_j l1.vdem_corr l1.civilconflict year if e(sample)

ssc install heatplot, replace
ssc install palettes, replace
ssc install colrspace, replace
matrix C = r(C)
heatplot C, values(format(%9.3f)) color(hcl, diverging intensity(.6)) legend(off) aspectratio(1) lower nodiagonal

********************************************************************************
* TABLE A5. Variance Inflation Factor 
sort cowcode year
gen Lcivilconflict = l1.civilconflict
gen Lvdem_corr = l1.vdem_corr 
gen Lh_polcon5 = l1.h_polcon5 
gen Ldemocracy = l1.democracy 
gen Lcombined_default = l1.combined_default 
gen Lgdppdc_log = l1.gdppdc_log 
gen Lreserves_gdp = l1.reserves_gdp 
gen Linflation = l1.inflation
gen Lh_j = l1.h_j
gen Lcurrentacct_gdp = l1.currentacct_gdp
gen Lresources_me = l1.resources_me
gen LGDPpcgrowth = l1.GDPpcgrowth
gen Ltrade_gdp = l1.trade_gdp

qui xtreg moody_rating_fc elite_education  newtech l1.combined_default  l1.gdppdc_log l1.GDPpcgrowth l1.currentacct_gdp l1.reserves_gdp l1.resources_me l1.trade_gdp l1.inflation l1.democracy l1.h_polcon5 l1.h_j l1.vdem_corr l1.civilconflict   year if year<=2015 & developing == 1, fe cluster(cowcode)

collin elite_education   newtech Lcivilconflict Lvdem_corr Lh_polcon5 Ldemocracy Lcombined_default Lgdppdc_log Lreserves_gdp Linflation Lh_j Lcurrentacct_gdp Ltrade_gdp LGDPpcgrowth Lresources_me year if year<=2015 & developing == 1 & e(sample)

********************************************************************************
* Table A6. Variable summary information

sum moody_rating_fc moody_rating_fc_t sp_rating_fc sp_rating_fc_t fitch_rating_fc fitch_rating_fc_t if developing == 1 & year <= 2015

sum  elite_education newtech combined_default gdppdc_log GDPpcgrowth currentacct_gdp reserves_gdp resources_me trade_gdp inflation democracy h_polcon5 h_j vdem_corr civilconflict year if developing == 1 & year <= 2015
